//index.js
//获取应用实例
var app = getApp()
var url = app.globalData.url;
Page({
  data: {
    userInfo: {},
    name:"",
    phone:"",
    num:"",
    title:'',
    weixin:''
  },
  //点击报名
  formSubmit: function (e) {

    
    if (e.detail.value.weixin.length == 0 || e.detail.value.name.length == 0 || e.detail.value.phone == 0 || e.detail.value.num.length == 0){
      wx.showModal({
        title: '提示',
        content: '在瞅瞅哪项没填',
        showCancel:false
      })
    }else{    
      var that=this;
      wx.request({
        url: `${url}add?name=${e.detail.value.name}&weixin=${e.detail.value.weixin}&phone=${e.detail.value.phone}&num=${e.detail.value.num}`, 
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
         
          wx.showToast({
            title: '报名成功',
            icon: 'success',
            duration: 1000
          }) 
    //报名成功清空input框   
          that.setData({
            name: "",
            phone: "",
            num: "",
            weixin:""
          })         
        }
      })
     
      setTimeout(function () {
        wx.navigateTo({
          url: '../detail/detail'
        })
      }, 1000)
    }
  },

  info(){
    wx.navigateTo({
      url: '../detail/detail'
    })
  },

  onLoad: function () {
    var that = this 
    wx.request({
      url: `${url}title`,
      header: {
        'content-type': 'application/json'
      },
      success: function (data) {
        that.setData({
           title:data.data[0].title
        })        
      }
    })

    app.getUserInfo(function(userInfo){
       that.setData({
         userInfo:userInfo
       })
    })

  }
})
